<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use app\admin\model\Product;
use app\admin\model\User;
use app\admin\model\ProductMessage as ProductMessageModel;

/**
 * 评论管理
 *
 * @icon   fa fa-list
 */
class ProductMessage extends Backend
{

    protected $model = null;
    protected $categorylist = [];
    protected $noNeedRight = ['selectpage'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new ProductMessageModel();
    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model
                ->where($where)
                ->where(['type'=>['in','0,1']])
                ->order($sort, $order)
                ->paginate($limit);
            foreach ($list as $k => $v) {
                $product =  Product::where(['id'=>$v['product_id']])->find();
                $list[$k]['product'] = $product['title'];
                $user =  User::where(['id'=>$v['user_id']])->find();
                $list[$k]['nickname'] = $user['nickname'];
            }
            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }

  
    /**
     * Selectpage搜索
     *
     * @internal
     */
    public function selectpage()
    {
        return parent::selectpage();
    }



}
